//
//  UIWebViewController.m
//  51易借
//
//  Created by 张睿 on 2017/9/29.
//  Copyright © 2017年 张睿. All rights reserved.
//

#import "UIWebViewController.h"

@interface UIWebViewController ()<UIWebViewDelegate>

@property (nonatomic,strong)UIWebView * webView;
@property (nonatomic,strong)UIView * topView;
@property (nonatomic,copy)NSString * url;

@end

@implementation UIWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupNavBar];
    [self setupUI];
}



- (void)setupNavBar{
    
    if ([self.count isEqualToString:@"1"]) {
        
        self.title = @"51易借注册协议";
        
    }else if ([self.count isEqualToString:@"2"]){
        
        self.title = @"帮助中心";
        
    }else if ([self.count isEqualToString:@"3"]){
        
        self.title = @"关于我们";
        
    }else if ([self.count isEqualToString:@"6"]){
        
        self.title = @"借款协议";
        
    }else if ([self.count isEqualToString:@"5"]){
        
        self.title = @"运行商授权协议";
    }else if ([self.count isEqualToString:@"7"]){
        
        self.title = @"平台服务协议";
    }else if ([self.count isEqualToString:@"8"]){
        
        self.title = @"授权扣款";
    }
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(15 * SCREENH6, 5 * SCREENH6, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"箭头"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToLastView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
}



- (void)setupUI{
    
//        self.edgesForExtendedLayout = UIRectEdgeNone;
//    self.automaticallyAdjustsScrollViewInsets = NO;
//    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView * topView = [UIView new];
    
    topView.backgroundColor = ColorWithRGB(0xff7907);
    
    self.topView = topView;
    
    [self.view addSubview:self.topView];
    //
    
    if ([self.count isEqualToString:@"1"]) {
        
        self.url = DEF_GET_OBJECT(@"registerProtocol");

    }else if ([self.count isEqualToString:@"2"]){
        
        self.url = DEF_GET_OBJECT(@"helpCenter");
        
    }else if ([self.count isEqualToString:@"3"]){
        
        self.url = DEF_GET_OBJECT(@"aboutCompany");
        
    }else if ([self.count isEqualToString:@"6"]){
        
        self.url = DEF_GET_OBJECT(@"loanProtocol");
        
    }else if ([self.count isEqualToString:@"5"]){
        
        self.url = DEF_GET_OBJECT(@"operatorAuthProtocol");
    }else if ([self.count isEqualToString:@"7"]){
        
        self.url = DEF_GET_OBJECT(@"platformServiceProtocol");
    }else if ([self.count isEqualToString:@"8"]){
        
        self.url = DEF_GET_OBJECT(@"authDeductDelegate");
    }
    

    CGFloat width = self.view.frame.size.width;
    CGFloat height = self.view.frame.size.height - 70 * SCREENH6;
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 70 * SCREENH6, width, height)];
    
    webView.delegate = self;
    webView.scalesPageToFit = YES;
    // 2.创建URL
    NSURL *url = [NSURL URLWithString:self.url];
    // 3.创建Request
    NSURLRequest *request =[NSURLRequest requestWithURL:url];
    // 4.加载网页
    [webView loadRequest:request];
    // 5.最后将webView添加到界面
    [self.view addSubview:webView];
    self.webView = webView;
    
    
}


- (void)viewDidLayoutSubviews{
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(64);
    }];
}


- (void)webViewDidFinishLoad:(UIWebView*)webView {
    
    
        [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '200%'"];
}

-(void)backToLastView
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
